package com.slliver.nacosconfig.controller;


import com.slliver.nacosconfig.properties.AdminUserProperties;
import com.slliver.nacosconfig.properties.CommonProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

// 加上 @RefreshScope 注解，可以对配置文件中的配置进行实时监听的功能
@RefreshScope
@RestController
public class GetConfigInfoController {

    @Value("${admin.user.nickname}")
    private String nickname;
    @Value("${admin.user.age}")
    private String age;
    @Value("${admin.user.phone}")
    private String phone;
    @Value("${admin.user.address}")
    private String address;


    @RequestMapping("/config")
    public String config() {
        return "实时获取配置文件中的配置信息 ==>> " + "\n"
                + "nickname => " + nickname + ",\n"
                + "age => " + age + ",\n"
                + "phone => " + phone + ",\n"
                + "address => " + address;
    }

    @Autowired
    private AdminUserProperties adminUserProperties;
    @Autowired
    private CommonProperties commonProperties;
    @RequestMapping("/admin/config")
    public String adminConfig() {
        return "实时获取配置文件中的配置信息 ==>> " + "\n"
                + "nickname => " + adminUserProperties.getNickname() + ",\n"
                + "age => " + adminUserProperties.getAge() + ",\n"
                + "phone => " + adminUserProperties.getPhone() + ",\n"
                + "address => " + adminUserProperties.getAddress() + "\n"
                + "url => " + commonProperties.getUrl() + ",\n"
                + "username => " + commonProperties.getUsername() + "\n"
                + "password => " + commonProperties.getPassword() + ",\n";
    }

}
